#!/usr/bin/python
import os
try:
    cpuLimit = 10.
    print "\n==========================================================================="
    print "  Lists all processes using more than %.1f%% CPU"%cpuLimit
    print "==========================================================================="
    for i in range(0,39):
        c = "comp%02i"%i
        print "\n---- %s ----------------------------------------------------------------"%c
        usrs = {}
        result = os.popen("ssh %s ps u -u root -U root -N  | awk '{print $1 \" \" $3 \" \" $4 \" \" $11}'"%c).readlines()[1:]
        for R in result:
            r = R.split()
            if float(r[1]) > cpuLimit:
                if r[0] not in usrs.keys(): usrs[r[0]] = []
                usrs[r[0]].append(r)
        if len(usrs.keys()) > 0:
            print "================================================="
            print "User\t\tCPU\tMEM\tProcess"
            print "================================================="
            for u in usrs.keys():
                for p in usrs[u]:
                    print "%-10s\t%s\t%s\t%s"%tuple(p)
except:
    print "there was a problem"
